package zblibrary.facechat.modules.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import zblibrary.facechat.R;
import zblibrary.facechat.databinding.FragmentHomeBinding;
import zblibrary.facechat.viewmodel.IHomeViewModel;
import zblibrary.facechat.viewmodel.impl.HomeViewModel;

public class HomeFragment extends Fragment {

    private IHomeViewModel mViewModel;

    public static HomeFragment newInstance() {
        HomeFragment fragment = new HomeFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        FragmentHomeBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false);
        mViewModel = new HomeViewModel(new HomeViewLayer(binding, this));
        mViewModel.bind();
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel.startRefresh(true);
    }

    @Override
    public void onDestroyView() {
        mViewModel.unbind();
        super.onDestroyView();
    }
}
